﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using System.Collections;
using Components;

namespace MsDAL
{
    public class ImportHelperDAL
    {
        private static ImportHelperDAL _entity;

        public static ImportHelperDAL Entity
        {
            get
            {
                if (null == _entity)
                    _entity = new ImportHelperDAL();

                return _entity;
            }
        }

        /// <summary>
        /// 向临时表中增加一条记录
        /// </summary>
        /// <param name="f1"></param>
        /// <returns></returns>
        public SqlApp InsertTemp(string f1)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Tmp(");
            strSql.Append("f1)");
            strSql.Append(" values (");
            strSql.Append("@f1 )");

            SqlParameter[] parameters = {
				new SqlParameter("@f1",SqlDbType.NVarChar)
				};
            parameters[0].Value = f1;

            return new SqlApp(strSql.ToString(), new ArrayList(parameters), false, "验证失败！");
        }

        /// <summary>
        /// 删除临时表
        /// </summary>
        /// <returns></returns>
        public SqlApp DeleteTmp(bool allowEmpty)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("DELETE FROM Tmp;");

            return new SqlApp(strSql.ToString(), null, allowEmpty, allowEmpty ? "" : "验证失败！");
        }

        /// <summary>
        /// 导入商品
        /// <param name="comcode">公司</param>
        /// </summary>
        public SqlApp ImportProdct(string comcode)
        {
            string sql = string.Format("sp_improduct '{0}'", comcode);

            return new SqlApp(sql, null, false, "");
        }

        /// <summary>
        /// 删除临时表
        /// </summary>
        /// <param name="allowEmpty"></param>
        /// <returns></returns>
        public SqlApp DeleteI11073(bool allowEmpty)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("DELETE FROM I11073;");

            return new SqlApp(strSql.ToString(), null, allowEmpty, allowEmpty ? "" : "验证失败！");
        }
    }
}
